﻿using System;
using System.Collections;
using System.Web;
using Deepcode.Flux.Core.Systems.CMS;

public class RequestCache
{
	public static IDictionary Current
	{
		get
		{
			if (HttpContext.Current == null) throw new InvalidOperationException();
			if (HttpContext.Current.Items == null) throw new InvalidCastException();
			return HttpContext.Current.Items;
		}
	}

	/// <summary>
	/// Gets the current known page ID.
	/// </summary>
	/// <value>The page ID.</value>
	public static int PageID
	{
		get
		{
			string nid = HttpContext.Current.Request["nodeid"];
			try
			{
				return Int32.Parse(nid);
			}
			catch
			{
				return -1;
			}
		}
	}

	/// <summary>
	/// Gets the current page node object
	/// </summary>
	/// <value>The node object.</value>
	public static ContentObject NodeObject
	{
		get
		{
			ContentObject obj = Current["Node"] as ContentObject;
			if (obj == null)
			{
				obj = ContentQuery.GetByID(PageID);
				Current["Node"] = obj;
			}

			return obj;
		}
	}
}
